copy file python

21

import shutil

original = r'original path where the file is currently stored\file name.file extension'
target = r'target path where the file will be copied\file name.file extension'

shutil.copyfile(original, target)
# Copy a file in Python using  copy() method
import shutil
shutil.copy( '/src/test/source.txt' , '/dest/destination.txt' )
# Copy a file in Python using  copy2() method
import shutil
shutil.copy2( '/src/test/source.txt' , '/dest/destination.txt' )
from shutil import copyfile
copyfile(src, dst)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Function              preserves     supports          accepts     copies other
                      permissions   directory dest.   file obj    metadata  
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
shutil.copy                                            ☐           ☐
shutil.copy2                                           ☐           
shutil.copyfile          ☐             ☐                 ☐           ☐
shutil.copyfileobj       ☐             ☐                            ☐

Comments

Submit
0 Comments